<template>
  <div>
    <Card dis-hover>
      <h3>
        {{ task.taskName }}
      </h3>
      <ButtonGroup slot="extra">
        <Button @click="approvalInfo" type="warning" style="background: #EF5350;" :loading="loading1"
                v-if="!task.viewFlag">
          <Icon type="ios-bookmark"/>
          审批
        </Button>
        <Button @click="returnTo">
          返回
          <Icon type="ios-arrow-forward"/>
        </Button>
      </ButtonGroup>
    </Card>
    <Row>
      <i-col>
        <Card dis-hover style="margin: 10px;">
          <div :style="{height: bodyHeight + 'px', overflowY: 'auto'}">
            <Tabs>
              <TabPane label="待办事项" v-if="!task.viewFlag && taskInfo.procinstState != '2'">
                <Form ref="formCustom" :model="formData" :rules="ruleCustom" label-position="top">
                  <Row>
                    <i-col span="8">
                      <FormItem label="审批结果：" prop="route">
                        <Select v-model="formData.route" @on-change="routePush">
                          <Option v-for="item in approveList" :value="item.value" :key="item.value">{{
                              item.text
                            }}
                          </Option>
                        </Select>
                      </FormItem>
                    </i-col>
                  </Row>
                  <Row>
                    <i-col span="8">
                      <FormItem label="处理意见：" prop="opinion">
                        <Input v-model="formData.opinion" type="textarea" :rows="2"/>
                      </FormItem>
                    </i-col>
                  </Row>
                </Form>
              </TabPane>
              <TabPane label="审计任务">
                <div style="margin-top: 50px">
                  <Form label-position="top">
                    <Row :gutter="16">
                      <i-col span="12">
                        <FormItem label="审计任务：" prop="planTaskName">
                          <Input v-model="auditData.missionName" readonly/>
                        </FormItem>
                      </i-col>
                      <i-col span="12">
                        <FormItem label="审计计划：" prop="auditedOrgName">
                          <Input v-model="auditData.auditPlanName" readonly/>
                        </FormItem>
                      </i-col>
                    </Row>
                    <Row :gutter="16">
                      <i-col span="8">
                        <FormItem label="审计基础标准：" prop="basicsName">
                          <Input v-model="auditData.basicsName" readonly/>
                        </FormItem>
                      </i-col>
                      <i-col span="8">
                        <FormItem label="审计现场标准：" prop="sceneName">
                          <Input v-model="auditData.sceneName" readonly/>
                        </FormItem>
                      </i-col>
                      <i-col span="8">
                        <FormItem label="审计班组标准：" prop="teamName">
                          <Input v-model="auditData.teamName" readonly/>
                        </FormItem>
                      </i-col>
                    </Row>
                    <Row>
                      <i-col span="12">
                        <FormItem label="被审计单位：" prop="auditedOrgName">
                          <Input v-model="auditData.auditedOrgName" readonly/>
                        </FormItem>
                      </i-col>
                      <i-col span="12">
                        <FormItem label="二级集团安全审计负责人：" prop="twoSafetyPersionName">
                          <Input v-model="auditData.twoSafetyPersionName" readonly/>
                        </FormItem>
                      </i-col>
                    </Row>
                    <Row :gutter="16">
                      <i-col span="12">
                        <FormItem label="开始时间：" prop="content">
                          <DatePicker class="query-form-el" type="date" style="width: 100%;"
                                      v-model="auditData.planStart"
                                      format="yyyy-MM-dd" readonly></DatePicker>
                        </FormItem>
                      </i-col>
                      <i-col span="12">
                        <FormItem label="结束时间：" prop="remark">
                          <DatePicker class="query-form-el" type="date" style="width: 100%;" v-model="auditData.planEnd"
                                      format="yyyy-MM-dd" readonly></DatePicker>
                        </FormItem>
                      </i-col>
                    </Row>
                  </Form>
                </div>
              </TabPane>
              <TabPane label="审计问题">
                <Table ref='table' :height="tableHeight" class="table" no-data-text="没有查询到相关数据！"
                       :loading="loading1"
                       size="small"
                       highlight-row stripe border :columns="columns1" width="100%" :data="dataTable"
                >
                </Table>
                <Row style="margin-right:10px;">
                  <Col span="24">
                    <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize"
                          @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                          show-total show-sizer show-elevator/>
                  </Col>
                </Row>
              </TabPane>
            </Tabs>
          </div>
        </Card>
      </i-col>
    </Row>
    <Modal title="审计问题整改" :transfer=false v-model="model12" class="modal-view-detail" :width=900
           :styles="{height:'600px'}">
      <Form :model="showdata" ref="showdata" :label-width="100" :rules="ruleCustom">
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="审计任务：">
              {{ showdata.planTaskName }}
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="审计单位：">
              {{ showdata.auditedOrgName }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="审计时间：" prop="auditTime">
              {{ this.formatDate(new Date(showdata.auditTime), 'yyyy-MM-dd') }}
            </FormItem>
          </Col>
          <Col span="11">

          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="项目：">
              {{ showdata.factorName }}
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="审计标准：">
              {{ showdata.executorName }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="审计内容：">
              {{ showdata.subitemName }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="扣分：" prop="auditScore">
              {{ showdata.auditScore }}
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="项目分值：">
              {{ showdata.factorScore }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">

          <Col span="23">
            <FormItem label="问题状态:">
              {{ showdata.problemStateName }}
            </FormItem>
          </Col>

        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="问题描述：" prop="rpoblemDesc">
              {{ showdata.rpoblemDesc }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="问题图片:">
              <div class="demo-upload-list" style="display:inline;margin:2px" v-for="item in upLoadList1"
                   :key="item.id">
                <img style="width:50px;height:50px;" @click="handleView(item.name,item.url)" :src="item.url">
              </div>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">

          <Col span="11">
            <FormItem label="整改人：" prop="personName">
              <Input type="text" v-model="showdata.personName"/>
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="整改人电话：" prop="phone">
              <Input type="text" v-model="showdata.phone"/>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="整改状态：" prop="verification">
              <Select v-model="showdata.verification">
                <Option value="0">整改中</Option>
                <Option value="1">已完成</Option>
              </Select>
            </FormItem>
          </Col>

          <Col span="11">
            <FormItem label='问题类别：' prop='problemCategory'>
              <Select v-model="showdata.problemCategory">
                <OptionGroup label="基础管理">
                  <Option v-for="item in sceneList" :value="item.codingCodeId" :key="item.codingCodeId">
                    {{ item.codingName }}
                  </Option>
                </OptionGroup>
                <OptionGroup label="现场管理">
                  <Option v-for="item in basicList" :value="item.codingCodeId"
                          :key="item.codingCodeId">{{ item.codingName }}
                  </Option>
                </OptionGroup>
              </Select>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label='完成时限：' prop='completeTime'>
              <DatePicker type="date" placeholder="请选择日期" style="width: 100%"
                          v-model='showdata.completeTime' :disabled="completeTime"
                          :editable="editable"></DatePicker>
            </FormItem>
          </Col>
          <Col span="11">

          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="整改方案：" prop="rectifyPlan">
              <Input v-model="showdata.rectifyPlan" type="textarea" :maxlength="500" show-word-limit :rows="3"/>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label='当前进展描述：'>
              <Input type='textarea' v-model='showdata.completion' :maxlength="1024" show-word-limit :rows="3"/>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="备注：">
              <Input v-model="showdata.note" type="textarea" :rows="3"/>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="整改后图片:">
              <div>
                <Upload ref="upload"
                        :before-upload="beforeUpload"
                        :show-upload-list="true"
                        :max-size="10240"
                        multiple
                        type="drag"
                        :action="fileUrl">
                  <div style="padding: 10px">
                    <Icon type="ios-cloud-upload" size="40" style="color: #3399ff"></Icon>
                    <p>点击将文件拖拽到这里上传</p>
                  </div>
                </Upload>
              </div>
              <div v-if="uploadItems.length > 0">
                <div v-for="item in uploadItems" :key='item.id'>
                  <a @click="downloadFiles(showdata.id,item)"><span
                      style="color: #3399ff;margin-left: 5px"> {{ item.fileName }}</span>
                  </a>
                  <a @click="remove1(showdata.id, item.id)"><span
                      style="color: #3399ff;margin-left: 5px">删除</span>
                  </a>
                </div>
              </div>
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' :loading="submitLoading" @click="submit('showdata')">确定</Button>
        <Button class='ivu-btn-cancel' @click="handleCancel">取消</Button>
      </div>
    </Modal>
    <Modal title="图片查看" v-model="visible">
      <img :src="viewUrl" v-if="visible" style="width: 100%">
      <div slot="footer">
        <Button @click="visible=false" class='ivu-btn-save'>关闭</Button>
      </div>
    </Modal>
    <Modal title="审计问题详情" :transfer=false v-model="model3" class-name='limit-height-dialog' :width=900
           :styles="{height:'600px'}">
      <Form ref="viewForm" :label-width="100">
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="审计任务：">
              {{ showdata.planTaskName }}
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="审计单位：">
              {{ showdata.auditedOrgName }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="审计时间：" prop="auditTime">
              {{ this.formatDate(new Date(showdata.auditTime), 'yyyy-MM-dd') }}
            </FormItem>
          </Col>
          <Col span="11">

          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="项目：">
              {{ showdata.factorName }}
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="审计标准：">
              {{ showdata.executorName }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="审计内容：">
              {{ showdata.subitemName }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="扣分：" prop="auditScore">
              {{ showdata.auditScore }}
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="项目分值：">
              {{ showdata.factorScore }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">

          <Col span="23">
            <FormItem label="问题状态:">
              {{ showdata.problemStateName }}
            </FormItem>
          </Col>

        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="问题描述：" prop="rpoblemDesc">
              {{ showdata.rpoblemDesc }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="问题图片:">
              <div class="demo-upload-list" style="display:inline;margin:2px" v-for="item in upLoadList1"
                   :key="item.id">
                <img style="width:50px;height:50px;" @click="handleView(item.name,item.url)" :src="item.url">
              </div>
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">

          <Col span="11">
            <FormItem label="整改人：">
              {{ showdata.personName }}
            </FormItem>
          </Col>
          <Col span="11">
            <FormItem label="整改人电话：">
              {{ showdata.phone }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="整改状态：">
              {{ showdata.verification === '0' ? '整改中' : showdata.verification === '1' ? '已完成' : '' }}
            </FormItem>
          </Col>

          <Col span="11">
            <FormItem label='问题类别：' prop='problemCategory'>
              {{ showdata.problemCategoryName }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="11">
            <FormItem label="完成时限：">
              {{ renderViewDate(showdata.completeTime) }}
            </FormItem>
          </Col>
          <Col span="11">

          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="整改方案：" prop="rectifyPlan">
              {{ showdata.rectifyPlan }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label='当前进展描述：'>
              {{ showdata.completion }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="备注：">
              {{ showdata.note }}
            </FormItem>
          </Col>
        </Row>
        <Row type="flex" justify="space-around" class="code-row-bg">
          <Col span="23">
            <FormItem label="整改后图片:">
              <div class="demo-upload-list" style="display:inline;margin:2px" v-for="item in uploadItems"
                   :key="item.id">
                <img style="width:50px;height:50px;" @click="handleView(item.name,item.url)" :src="item.url">
              </div>
            </FormItem>
          </Col>
        </Row>
      </Form>
      <div slot="footer">
        <Button class='ivu-btn-save' @click="onCancel">关闭</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import {sessionStorage} from '@/common/cacheUtils.js';
import {Api} from '../../../api'
import {formatDate} from "@/tools";
// import workflowForm from "@/components/workflowForm.vue"
export default {
  data() {

    return {
      model12: false,
      showdata: {},
      model3: false,
      completeTime: null,
      submitLoading: false,
      basicList: [],
      sceneList: [],
      editable: false,
      pagedata: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      tableHeight: '',
      viewUrl: '',
      approveList: [
        {
          text: "通过",
          value: "1"
        },
        {
          text: "不通过",
          value: "2"
        }
      ],
      ruleCustom1: {
        personName: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        phone: [{
          validator: (rule, value, callback) => {
            if (!(/^1[3456789]\d{9}$/.test(value))) {
              callback(' ');
              // this.$Message.error("请填写有效的的手机号")
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'blur'
        }],

        verification: [{
          validator: (rule, value, callback) => {
            if (this.showdata.verification == null || this.showdata.verification == '' || this.showdata.verification == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        problemCategory: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        rectifyPlan: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],
        completeTime: [{
          validator: (rule, value, callback) => {
            if (value == null || value == '' || value == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],

      },
      uploadItems: [],
      columns1: [
        {
          title: "序号",
          width: 80,
          align: "center",
          fixed: 'left',
          render: (h, params) => {
            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
          }
        },
        {
          title: "整改状态",
          width: 150,
          align: "center",
          fixed: 'left',
          render: (h, params) => {
            let color = 'green';
            if (params.row.verification == undefined || params.row.verification == null || params.row.verification === '0') {
              color = 'red';
            }
            return h('div', [
              h('span', {
                style: {
                  color: color
                }
              }, params.row.verification === '1' ? '已整改' : '未整改')
            ]);
          }
        },
        {
          minWidth: 300,
          title: '问题描述',
          key: 'rpoblemDesc',
          align: 'center',
          tooltip: true
        },
        {
          minWidth: 180,
          title: '审计标准',
          key: 'executorName',
          align: 'center',
          tooltip: true
        },
        {
          minWidth: 180,
          title: '项目',
          key: 'factorName',
          align: 'center',
          tooltip: true
        },
        {
          minWidth: 180,
          title: '审计内容',
          key: 'subitemName',
          align: 'center',
          tooltip: true

        },
        {
          minWidth: 180,
          title: '项目分值',
          key: 'factorScore',
          align: 'center',
        },
        {
          minWidth: 180,
          title: '扣分',
          key: 'auditScore',
          align: 'center',
        },

        // {
        //   minWidth: 250,
        //   title: '问题图片',
        //   align: 'center',
        //   key: 'imgsrc',
        //   render: (h, params) => {
        //     let ps = params.row.pictureId.split(':')
        //     let hFn = []
        //     ps.forEach(v => {
        //       if (v) {
        //         let url = this.fileUrl + '/file/' + v
        //         hFn.push(
        //             h('img', {
        //               style: {
        //                 width: "30px",
        //                 margin: "3px",
        //                 cursor: "pointer"
        //               },
        //               attrs: {
        //                 src: url
        //               },
        //               on: {
        //                 click: () => {
        //                   this.handleView('', url)
        //                 }
        //               }
        //             })
        //         )
        //       }
        //     })
        //     return h('div', [...hFn
        //     ]);
        //   }
        // },
        {
          title: '操作',
          key: 'action',
          fixed: 'right',
          minWidth: 150,
          align: 'center',
          render: (h, params) => {
            if (this.taskInfo.procinstState == '2') {
              return h('div', [

                h('A', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    fontSize: '14px'
                  },
                  on: {
                    click: () => {
                      this.showData(params, 1);
                    }
                  }
                }, '详情'),
                h('Divider', {
                  props: {
                    type: 'vertical',
                  }
                }, ''),
                h('A', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    fontSize: '14px',
                  },
                  on: {
                    click: () => {
                      this.showData(params, 2);
                    }
                  }
                }, '整改'),
              ]);
            } else {
              return h('div', [

                h('A', {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    fontSize: '14px'
                  },
                  on: {
                    click: () => {
                      this.showData(params, 1);
                    }
                  }
                }, '详情'),

              ]);
            }


          }
        }
      ],
      dataTable: [],
      fileImgSrc: false,
      loading1: false,
      single: true,
      ifDynamicAudits: false,
      isModifyFile: false,
      isDepartment: false,
      departmentName: '',
      isDepartmentUser: false,
      isRectifyrp: false,
      isRectifyrecord: false,
      isIntervention: false,
      isRole: false,
      isDivisionRoute: false,
      isReportFile: false,
      roleName: '',
      user: sessionStorage('userId').getObject('userId'),
      formData: {},
      ruleCustom: {
        opinion: [{
          validator: (rule, value, callback) => {
            if (this.formData.opinion == null || this.formData.opinion == '' || this.formData.opinion == undefined) {
              callback(' ')
            } else {
              callback()
            }
          },
          required: true,
          trigger: 'change'
        }],

        route: [
          {required: true, message: '  ', trigger: 'blur'}
        ]
      },
      bodyHeight: '',
      footerHeight: 100,
      routeList: [
        {
          id: 1,
          name: '合格'
        },
        {
          id: 2,
          name: '不合格'
        }
      ],
      visible: false,
      taskInfo: this.$route.query,
      fileUrl: Api.interestedPartiesUserFile,
      apsgData: {},
      upLoadList1: [],
      upLoadList2: [],
      reportFile: [],
      modifyFile: [],
      fileList: [],
      userList: [],
      userList2: [],
      auditData: {},
      task:{},
      interventionList: [
        {
          id: "1",
          name: '是'
        },
        {
          id: "2",
          name: '否'
        }
      ],
      roleUserList: []
    }
  },
  mounted() {
    this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 300;
    this.bodyHeight = window.innerHeight - 180
    this.$http.get(Api.queryCodeDetailBySuperiorcode + '/NOT-00007000000001', {params: {}}).then((res) => {
      this.basicList = res.data.data;
    });
    this.$http.get(Api.queryCodeDetailBySuperiorcode + '/NOT-00007000000004', {params: {}}).then((res) => {
      this.sceneList = res.data.data;
    });
    this.task = this.$route.query;
    if (this.$route.query.close == false) {
      this.$http.get(Api.getUserByUserId + this.$route.query.userId)
          .then(function (res) {
            this.user = res.data.data;
            this.$http.get(Api.getTaskData + "/" + this.$route.query.procinstId + "/" +
                this.$route.query.taskId + "?close=" + this.$route.query.close).then(function (res1) {
              this.taskInfo = res1.data;
              if (res1.data.viewFlag == false)
                this.task.viewFlag = false;
              else
                this.task.viewFlag = true;
              this.load();
              return ;
            })
          })
    }else{
      var search=window.location.href.split('?')[1];//截取URL？后面的参数
      var params={};
      if(search!=""&&search!=undefined){
        search.split("&").forEach(
            function(val){
              var arr=val.split("=");
              params[arr[0]]=arr[1];
            }
        )}
      var code=params.code
      var status = params.status
      if(code != null && code != 'undefine'){
        this.$http.get(Api.queryToken, {
          params: {
            code: code,
          }
        }).then(res1 => {
          if(res1.data.errcode == "1014"){
            this.$http.get(Api.getReZheng).then(res2=>{
              window.location.href = decodeURIComponent(res2.bodyText) + "&redirect_uri="+encodeURIComponent(window.location.href);
            })
          }
          else{
            this.$http.get(Api.getUserByUserId + this.$route.query.userId)
                .then(function(res){
                  this.user = res.data.data;
                  this.$http.get(Api.getTaskData + "/" + this.$route.query.procinstId + "/" +
                      this.$route.query.taskId+"?close="+this.$route.query.close).then(function(res1){
                    this.taskInfo = res1.data;
                    if(res1.data.viewFlag == false)
                      this.taskInfo.viewFlag = false;
                    else
                      this.taskInfo.viewFlag = true;
                    this.load();
                    return ;
                  })
                })
          }
        })
      }
      else{
        this.$http.get(Api.getReZheng).then(res2=>{
          window.location.href = decodeURIComponent(res2.bodyText) + "&redirect_uri="+encodeURIComponent(window.location.href);
        });
      }
    }


  },
  methods: {
    renderViewDate(date) {
      if (!date) return "";
      return formatDate(new Date(date), "yyyy-MM-dd");
    },
    load() {
      let _this = this;

      this.$http.get(Api.getSaProinst + this.taskInfo.procinstId).then((res) => {

        _this.taskInfo = res.data.data;
        _this.loadDataTable();
        _this.loadDataMission();
      }).catch(e => {

        this.$Message.error("数据获取失败")
      })
    },
    loadDataMission() {
      let _this = this;
      let url = Api.queryProblemRect;
      this.$http.get(url + this.taskInfo.workId).then((res) => {

        _this.auditData = res.data.data;

      }).catch(e => {
        console.log(e)
        this.$Message.error("数据获取失败")
      })
    },
    onCancel() {
      this.model3 = false
    },
    remove1(mainId, id) {
      let url = this.fileUrl + '/file/' + id;
      this.$http.delete(url).then((res) => {
        var index = this.uploadItems.indexOf(id);
        if (index > -1) {
          this.uploadItems.splice(index, 1);
        }
        this.getFilesItem(mainId)
      })
    },
    beforeUpload(file) {
      let formData = new FormData();
      formData.append("files", file); // 文件对象
      let url = this.fileUrl + '/' + this.showdata.id + '/files/picture/adtProblems'
      this.$http.post(url, formData).then((res) => {
        if (res.data.result == "success") {
          this.$Message.info("文件上传成功")
          this.getFilesItem(this.showdata.id);
        }
      })
      return false
    },
    async getFiles(id) {
      this.upLoadList1.length = 0
      let url = this.fileUrl + '/' + id + '/files/picture'
      let data = {field: 'adtProblems'}
      await this.$http.get(url, {params: data}).then((res) => {
        if (res.data.result == "success") {
          if (res.data.data) {
            this.upLoadList1 = res.data.data
            this.upLoadList1 = this.upLoadList1.map(v => {
              v.url = this.fileUrl + '/file/' + v.id;
              return v
            })
          }
        }
      })
    },
    async getFilesItem(id) {
      this.uploadItems.length = 0
      let url = this.fileUrl + '/' + id + '/files/picture'
      let data = {field: 'adtProblems'}
      await this.$http.get(url, {params: data}).then((res) => {
        if (res.data.result == "success") {
          if (res.data.data) {
            this.uploadItems = res.data.data
            this.uploadItems = this.uploadItems.map(v => {
              v.url = this.fileUrl + '/file/' + v.id;
              return v
            })
          }
        }
      })
    },
    async showData(data, flag) {
      let _this = this
      data.row.createDate = this.formatDate(new Date(data.row.createDate), 'yyyy-MM-dd')
      this.getFiles(data.row.problemId)
      this.getFilesItem(data.row.id)
      _this.completeTime = data.row.completeTime
      if (flag == 1) {
        this.showdata = data.row;
        this.model3 = true;
      } else {
        _this.showdata = JSON.parse(JSON.stringify(data.row));
        if (_this.showdata.id == null) {
          _this.showdata.id = _this.get_uuid();
          _this.showdata.personName = _this.user.userName;
          _this.showdata.phone = _this.user.mobileNumber;
          _this.showdata.verification = '0'
          _this.showdata.missionId = _this.showdata.problemId

        }
        this.model12 = true;
      }
    },
    handleView(name, url) {
      this.viewUrl = url;
      this.imgName = name;
      this.visible = true;
    },
    pageChange(pageNum) {
      this.pagedata.currentPage = pageNum;
      this.loadDataTable();
    },
    pageSizeChange(pageSize) {
      this.pagedata.pageSize = pageSize;
      this.loadDataTable();
    },
    loadDataTable() {
      let _this = this;
      _this.loading1 = true
      let data = {
        startPage: this.pagedata.currentPage,
        size: this.pagedata.pageSize,
        id: this.taskInfo.workId,
      }
      let url = Api.queryRectificationList;
      this.$http.get(url, {params: data}).then((res) => {
        _this.loading1 = false
        this.dataTable = res.data.data.data;
        this.pagedata.total = res.data.data.totalSize;
      }).catch(e => {
        console.log(e)
        this.$Message.error("数据获取失败")
      })
    },
    routePush(value) {
      if (value === '1') {
        this.formData.opinion = "同意";
      } else {
        this.formData.opinion = null;
      }
    },
    handleCancel() {

      this.model12 = false;

    },
    returnTo() {
      if(this.taskInfo.close == true){
        window.close();
      } else{
        this.$router.go(-1);
      }

    },
    formatDate(date, fmt) {
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
      };
      for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
          let str = o[k] + '';
          fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
        }
      }
      return fmt;
    },
    get_uuid() {
      let s = [];
      let hexDigits = "0123456789abcdef";
      for (let i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
      }
      s[14] = "4";
      s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
      s[8] = s[13] = s[18] = s[23] = "-";

      let uuid = s.join("");
      let reg = new RegExp("-", "g");
      let a = uuid.replace(reg, "");
      return a;
    },
    padLeftZero(str) {
      return ('00' + str).substr(str.length);
    },
    submit(name) {
      let _this = this;
      this.$refs[name].validate((valid) => {
        if (valid) {
          this.submitLoading = true;
          let userId = sessionStorage('userId').getObject('userId').userId;
          let orgId = sessionStorage('userId').getObject('userId').orgInfo.orgId;
          this.showdata.updateUserId = userId;
          this.showdata.updateOrgId = orgId;
          this.$http.post(Api.saveRectificationList, this.showdata).then((res) => {
            if (res.data.status == '200') {
              this.$Message.success('成功');
              this.model12 = false;
              this.loadDataTable()

            } else if (res.data.status == '201') {
              this.$Message.error(res.data.data);
              this.model12 = false;
            }
            _this.submitLoading = false;

          }).catch(e => {
            _this.submitLoading = false;
            this.model12 = false;
            this.loadDataTable()
            this.$Message.error("数据获取失败")
          })


        } else {
          this.$Message.error('请填报完整!');
        }
      })
    },
    //审批
    approvalInfo() {
      let _this = this;

      if (this.taskInfo.procinstState == '2') {
        _this.loading1 = true;
        let data = {
          createUserId: this.user.userId,
          userName: this.user.userName,
          opinion: '同意',
          taskId: this.taskInfo.taskId,
          procinstId: this.taskInfo.procinstId,
          route: '1'
        };
        this.$http.get(Api.taskComplete, {params: data}).then((res) => {
          _this.loading1 = false;
          if (res.data.status == '200') {
            this.$Message.success("审批成功")
            this.returnTo();
          } else {
            this.$Message.success("审批失败")
          }
        }).catch(e => {
          this.loading1 = false;
          this.$Message.error("数据获取失败")
        })
      } else {
        this.$refs['formCustom'].validate((valid) => {
          if (valid) {
            debugger;
            _this.loading1 = true;
            let data = {
              createUserId: this.user.userId,
              userName: this.user.userName,
              opinion: this.formData.opinion,
              taskId: this.taskInfo.taskId,
              procinstId: this.taskInfo.procinstId,
              route: this.formData.route
            };
            this.$http.get(Api.taskComplete, {params: data}).then((res) => {
              _this.loading1 = false;
              if (res.data.status == '200') {
                this.$Message.success("审批成功")
                this.returnTo();
              } else {
                this.$Message.success("审批失败")
              }
            }).catch(e => {
              _this.loading1 = false;
              this.$Message.error("数据获取失败")
            })


          } else {
            this.$Message.error('请填报完整!');
          }
        });
      }
    },
  }
}
</script>
<style scoped>
.demo-upload-list {
  display: inline-block;
  width: 60px;
  height: 60px;
  text-align: center;
  line-height: 60px;
  border: 1px solid transparent;
  border-radius: 4px;
  overflow: hidden;
  background: #fff;
  position: relative;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
  margin-right: 4px;
}

.demo-upload-list img {
  width: 100%;
  height: 100%;
}

.demo-upload-list-cover {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, .6);
}

.demo-upload-list:hover .demo-upload-list-cover {
  display: block;
}

.demo-upload-list-cover i {
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  margin: 0 2px;
}

.ivu-row {
  flex-flow: row wrap;
}
</style>
<style scoped>

</style>
